﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UpDownLoadControl.ascx.cs"
	Inherits="Basic4Net.OAWeb.CustomControl.UpDownLoadControl" %>
<table id="<%=this.ClientID %>_Root" width="100%" border="0" cellpadding="0" cellspacing="0" style="border: 0px">
	<tr>
		<td align="left" style="border: 0px; text-align: left">
			<table align="left" id="tabFiles" runat="server" cellpadding="0" style="border: 0px"
				cellspacing="0">
				<tr style="border: 0px">
					<td style="border: 0px; text-align: left;">
						<input id="<%=this.ClientID %>_file0" name="file0" type="file" contenteditable="false"
							onchange="<%=this.ClientID %>CreateFile(this);" />
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td id="theFilesShow" runat="server" style="border: 0px; text-align: left; display: none;">
		</td>
	</tr>
</table>
<input id="HideDeleteIDs" type="hidden" runat="server" value="," />
<script type="text/javascript" language="javascript">
var <%=this.ClientID %>Max=<%= MaxNumber %>;
var <%=this.ClientID %>i=0;
function <%=this.ClientID %>GetNumber()
{
	var nRow = document.getElementById('<%=this.ClientID %>_tabFiles').rows.length;
	return nRow-1;
}

function <%=this.ClientID %>DeleteLine(Obj, spanId, serverHidden1)
{
	if (document.getElementById(spanId).style.textDecoration == "line-through")
	{
		document.getElementById(spanId).style.textDecoration = "";
		Obj.alt = "删除";
		document.getElementById('<%=this.ClientID %>_HideDeleteIDs').value = document.getElementById('<%=this.ClientID %>'+"_HideDeleteIDs").value.replace(","+document.getElementById(serverHidden1).value+",",",");
		
	}
	else
	{
		document.getElementById(spanId).style.textDecoration = "line-through";
		Obj.alt = "取消删除";
		document.getElementById('<%=this.ClientID %>_HideDeleteIDs').value += document.getElementById(serverHidden1).value + ',';
	}
}

function <%=this.ClientID %>Delete(Obj,Id)
{
	Obj.removeNode(true);
	document.getElementById('<%=this.ClientID %>_span'+Id).removeNode(true);
	document.getElementById('<%=this.ClientID %>_br'+Id).removeNode(true);

	if (document.getElementById('<%=this.ClientID %>_theFilesShow').innerHTML == "")
		document.getElementById('<%=this.ClientID %>_theFilesShow').style.display = "none";

	currRowIndex = document.getElementById('<%=this.ClientID %>_file'+Id).parentNode.parentNode.rowIndex;
	document.getElementById('<%=this.ClientID %>_tabFiles').deleteRow(currRowIndex);

	document.getElementById('<%=this.ClientID %>_file'+<%=this.ClientID %>i).parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "";
}

function <%=this.ClientID %>CreateFile(Obj)
{
		var FileName = <%=this.ClientID %>base_name(Obj.value);
	
		if (document.getElementById('<%=this.ClientID %>_theFilesShow').style.display == "none")
			document.getElementById('<%=this.ClientID %>_theFilesShow').style.display = "";

		document.getElementById('<%=this.ClientID %>_theFilesShow').innerHTML += //'<span id="<%=this.ClientID %>_span'+<%=this.ClientID %>i+'">'+ FileName +'</span><img id="<%=this.ClientID %>_delete'+<%=this.ClientID %>i+'" alt="删除" src="<%=Page.ResolveClientUrl("~/App_Themes/ui-lightness/ProjectImages/del.gif")%>"  onclick="<%=this.ClientID %>Delete(this,"BR<%=this.ClientID %>'+<%=this.ClientID %>i+ '","<%=this.ClientID %>_span'+<%=this.ClientID %>i+'", "<%=this.ClientID %>_file'+<%=this.ClientID %>i+ '");"/><br id="BR<%=this.ClientID %>'+<%=this.ClientID %>i +'"/>';
	
		"<span id='<%=this.ClientID %>_span"+<%=this.ClientID %>i+"'>"+ FileName +"</span>"+
		"<img id='<%=this.ClientID %>_delete"+<%=this.ClientID %>i+"' alt='删除' src='"+'<%=Page.ResolveClientUrl("~/App_Themes/ui-lightness/ProjectImages/del.gif")%>'+"' onclick='<%=this.ClientID %>Delete(this,"+<%=this.ClientID %>i+");'  />"+
		"<br id='<%=this.ClientID %>_br"+<%=this.ClientID %>i+"' />"

		Obj.parentNode.parentNode.style.display = "none";
		<%=this.ClientID %>i++;
		
		var nRow = document.getElementById('<%=this.ClientID %>_tabFiles').rows.length; 
		var objTheRow = document.getElementById('<%=this.ClientID %>_tabFiles').insertRow(nRow);
		var objTheCell = objTheRow.insertCell(0);//添加当前行的列
		
		objTheCell.style.border = "0px"; 
		objTheCell.style.textAlign = "left"; 
		//objTheCell.outerHTML='<td style="border: 0px; text-align: left;">' + '<input onchange="<%=this.ClientID %>CreateFile(this);" contenteditable="false" id="<%=this.ClientID %>_file'+<%=this.ClientID %>i+'" name="file'+<%=this.ClientID %>i+'" type="file" />' + "</td>";
		objTheCell.innerHTML='<input onchange="<%=this.ClientID %>CreateFile(this);" contenteditable="false" id="<%=this.ClientID %>_file'+<%=this.ClientID %>i+'" name="file'+<%=this.ClientID %>i+'" type="file" />';

		if (nRow >= <%=this.ClientID %>Max)
			document.getElementById('<%=this.ClientID %>_file'+<%=this.ClientID %>i).parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "none";
}

//取文件名
function <%=this.ClientID %>base_name(pFilePath)
{
    var temp_win = pFilePath.lastIndexOf("\\");
    var temp_unix = pFilePath.lastIndexOf("/");
    if (temp_win>0)
    {
        temp = temp_win;
    }
    else if (temp_unix>0)
    {
        temp = temp_unix;
    }
    else
    {
        temp = -1;    
    }
    file_name = pFilePath.substr(temp+1);

	if (file_name.length > 15)
		return file_name.substring(0,12) + "...";
	else
		return(file_name);
}
</script>
